gdk: seal in-memory files when possible
authoremersion <contact@emersion.fr>
Sun, 23 Sep 2018 18:56:18 +0000 (20:56 +0200)
committeremersion <contact@emersion.fr>
Thu, 27 Sep 2018 21:35:18 +0000 (23:35 +0200)
This can be used by compositors to mmap memory without having to
handle SIGBUS.

gdk/wayland/gdkdisplay-wayland.c

index 712112b56585b41eafb999c49d11b7ef4c7b46b3..7bcf18ca30ece41f19d7a4c253666ed6e13c9570 100644 (file)
@@ -1207,13 +1207,21 @@ open_shared_memory (void)
 #if defined (__NR_memfd_create)
       if (!force_shm_open)
         {
-          ret = syscall (__NR_memfd_create, "gdk-wayland", MFD_CLOEXEC);
+          int options = MFD_CLOEXEC;
+#if defined (MFD_ALLOW_SEALING)
+          options |= MFD_ALLOW_SEALING;
+#endif
+          ret = syscall (__NR_memfd_create, "gdk-wayland", options);
 
           /* fall back to shm_open until debian stops shipping 3.16 kernel
            * See bug 766341
            */
           if (ret < 0 && errno == ENOSYS)
             force_shm_open = TRUE;
+#if defined (F_ADD_SEALS) && defined (F_SEAL_SHRINK)
+          if (ret >= 0)
+            fcntl (ret, F_ADD_SEALS, F_SEAL_SHRINK);
+#endif
         }
 #endif